package com.maimao.model.user.sys.vo;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.*;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;
import java.util.List;

/**
 * 登录用户的所有权限(角色名列表和资源名列表)
 * @author MaoLin Wang
 * @date 2020/11/30 9:10 下午
 */
@Setter
@Getter
@Builder
@AllArgsConstructor
@NoArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Permissions implements Serializable {
    private Long id;

    private String username;

    private String password;

    private String realName;


    private Long shopId;
    private String mobile;

    private String avatar;

    private List<String> roles;

    private List<String>resources;

    private String permissionStr;

    @Override
    public String toString() {
        return "Permissions{" +
                "id=" + id +
                ", username='" + username + '\'' +
                ", password='" + password + '\'' +
                ", realName='" + realName + '\'' +
                ", shopId=" + shopId +
                ", mobile='" + mobile + '\'' +
                ", avatar='" + avatar + '\'' +
                ", roles=" + roles +
                ", resources=" + resources +
                ", permissionStr='" + permissionStr + '\'' +
                '}';
    }

    public String getPermissionStr() {
        String roleNames="";
        if (roles!=null && roles.size()>0){
            roleNames = StringUtils.join(this.roles, ",");
        }
        String permissionNames="";
        if (resources!=null && resources.size()>0){
            permissionNames=StringUtils.join(this.resources,",");
        }
        if (StringUtils.isEmpty(roleNames)){
            return permissionNames;
        }
        if (StringUtils.isEmpty(permissionNames)){
            return roleNames;
        }
        return roleNames+","+permissionNames;
    }
}
